package top.swimmer.tools.data.linked;

public class ListNodeCycle {
    public static boolean listNodeCycle(ListNode node) {
        if (node == null || node.next == null) {
            return false;
        }

        ListNode fast = node.next;
        ListNode slow = node;

        while (slow != fast) {
            if (fast == null || fast.next == null) {
                return false;
            }
            fast = fast.next.next;
            slow = slow.next;
        }
        return true;
    }
}
